#include "config_main.h"
#ifdef DDENN_INS_GARMIN_GMA_340
/*
 * ins_garmin_gma_340.c
 *
 *  Created on: 06.06.2009
 *      Author: Admin
 */

#include "ins_garmin_gma_340.h"





/**************************************************************************************/
//
//          it provides ddenn/instruments/garmin_gma_340/
//
/*************************************************************************************/


int DdennGarminGma340::DDennGarminGmaPower = 1;


void DdennGarminGma340::RegisterDdennGarminGma340(){

	XPLMRegisterDataAccessor( "ddenn/instruments/garmin_gma_340/power" ,    xplmType_Int, 1,
				                                   GetInsGarminGmaPower,
				                                   SetInsGarminGmaPower,NULL,NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);
	XPLMRegisterDataAccessor( "ddenn/instruments/garmin_gma_340/marker_enabled" ,    xplmType_Int, 1,
				                                   GetInsGarminGmaAudioMarker,
				                                   SetInsGarminGmaAudioMarker,NULL,NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);
	XPLMRegisterDataAccessor( "ddenn/instruments/garmin_gma_340/dme_enabled" ,    xplmType_Int, 1,
				                                   GetInsGarminGmaDme,
				                                   SetInsGarminGmaDme,NULL,NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);
	XPLMRegisterDataAccessor( "ddenn/instruments/garmin_gma_340/com_selection" ,    xplmType_Int, 1,
				                                   GetInsGarminGmaComSelection,
				                                   SetInsGarminGmaComSelection,NULL,NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);
	XPLMRegisterDataAccessor( "ddenn/instruments/garmin_gma_340/nav_selection" ,    xplmType_Int, 1,
				                                   GetInsGarminGmaNavSelection,
				                                   SetInsGarminGmaNavSelection,NULL,NULL,NULL, NULL,NULL,NULL,NULL,  NULL,NULL,    NULL,  NULL,NULL);



}

void DdennGarminGma340::UnregisterDdennGarminGma340(){


	XPLMUnregisterDataAccessor( XPLMFindDataRef( "ddenn/instruments/garmin_gma_340/power"  ));
	XPLMUnregisterDataAccessor( XPLMFindDataRef( "ddenn/instruments/garmin_gma_340/marker_enabled"  ));
	XPLMUnregisterDataAccessor( XPLMFindDataRef( "ddenn/instruments/garmin_gma_340/dme_enabled" ));
	XPLMUnregisterDataAccessor( XPLMFindDataRef( "ddenn/instruments/garmin_gma_340/com_selection" ));
	XPLMUnregisterDataAccessor( XPLMFindDataRef( "ddenn/instruments/garmin_gma_340/nav_selection" ));


}


bool DdennGarminGma340::IsPowered(){
 return (DDennGarminGmaPower&&IsMainPowerOn(1));
}


int DdennGarminGma340::GetInsGarminGmaPower ( void *               inRefcon)
{

	return IsPowered();
}


void DdennGarminGma340::SetInsGarminGmaPower(void *               inRefcon,
                 int                  inValue)
{
	if (inValue&&IsMainPowerOn(1)){
      if (!DDennGarminGmaPower){
		DDennGarminGmaPower=1;
		if (GetDataRefI("sim/cockpit2/radios/actuators/audio_marker_enabled")==0) SetDataRefI("sim/cockpit2/radios/actuators/audio_marker_enabled",1);
		if (GetDataRefI("sim/cockpit2/radios/actuators/audio_dme_enabled")==0) SetDataRefI("sim/cockpit2/radios/actuators/audio_dme_enabled",1);
		if (GetDataRefI("sim/cockpit2/radios/actuators/audio_nav_selection")==9) SetDataRefI("sim/cockpit2/radios/actuators/audio_nav_selection",9);
		if (GetDataRefI("sim/cockpit2/radios/actuators/audio_com_selection")==8) SetDataRefI("sim/cockpit2/radios/actuators/audio_com_selection",6);
      }
	}else{
		DDennGarminGmaPower=0;
		SetDataRefI("sim/cockpit2/radios/actuators/audio_marker_enabled",0);
		SetDataRefI("sim/cockpit2/radios/actuators/audio_dme_enabled",0);
		SetDataRefI("sim/cockpit2/radios/actuators/audio_nav_selection",9);
		SetDataRefI("sim/cockpit2/radios/actuators/audio_com_selection",8);
	};


}


int DdennGarminGma340::GetInsGarminGmaAudioMarker ( void *               inRefcon)
{

	if (IsPowered())
		return GetDataRefI("sim/cockpit2/radios/actuators/audio_marker_enabled");
	else
		return 0;
}

void DdennGarminGma340::SetInsGarminGmaAudioMarker(void *               inRefcon,
                 int                  inValue)
{
	if (IsPowered()){
		SetDataRefI("sim/cockpit2/radios/actuators/audio_marker_enabled",inValue);
	}
}


int DdennGarminGma340::GetInsGarminGmaDme ( void *               inRefcon)
{
	if (IsPowered())return GetDataRefI("sim/cockpit2/radios/actuators/audio_dme_enabled");
	else return 0;
}


void DdennGarminGma340::SetInsGarminGmaDme(void *               inRefcon,
                 int                  inValue)
{
	if (IsPowered()){
		SetDataRefI("sim/cockpit2/radios/actuators/audio_dme_enabled",inValue);
	}
}




int DdennGarminGma340::GetInsGarminGmaNavSelection ( void *               inRefcon)
{

	if (IsPowered()) return GetDataRefI("sim/cockpit2/radios/actuators/audio_nav_selection");
	else return 9;
}

void DdennGarminGma340::SetInsGarminGmaNavSelection(void *               inRefcon,
                 int                  inValue)
{
	if (DDennGarminGmaPower){
		SetDataRefI("sim/cockpit2/radios/actuators/audio_nav_selection",inValue);
	}
}

int DdennGarminGma340::GetInsGarminGmaComSelection ( void *               inRefcon)
{
	if (IsPowered()){
			return GetDataRefI("sim/cockpit2/radios/actuators/audio_com_selection");
	}else return 8;
}
void DdennGarminGma340::SetInsGarminGmaComSelection(void *               inRefcon,
                 int                  inValue)
{
	if (IsPowered()){
		SetDataRefI("sim/cockpit2/radios/actuators/audio_com_selection",inValue);
	}
}

/**************************************************************************************/
//
//         end of ddenn/instruments/garmin_gma_340/
//
/*************************************************************************************/

#endif
